-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Ensure that input_guardrails can block tools from running #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This PR is stale because it has been open for 10 days with no activity. |
This PR was closed because it has been inactive for 7 days since being marked as stale. |
@rm-openai do you think this approach is still good to go? If not, we may want to think of a solution for #889 and #991 |
This PR is stale because it has been open for 10 days with no activity. |
Hi @seratch, just checked out on the PR and tried the following script (a shorter version of the quickstart script) - it still does not block the call.
from agents import Agent, InputGuardrail, GuardrailFunctionOutput, Runner
from agents.exceptions import InputGuardrailTripwireTriggered
from pydantic import BaseModel
import asyncio
class HomeworkOutput(BaseModel):
is_homework: bool
reasoning: str
guardrail_agent = Agent(
name="Guardrail check",
instructions="Check if the user is asking about homework.",
output_type=HomeworkOutput,
)
math_tutor_agent = Agent(
name="Math Tutor",
handoff_description="Specialist agent for math questions",
instructions="You provide help with math problems. Explain your reasoning at each step and include examples",
)
async def homework_guardrail(ctx, agent, input_data):
result = await Runner.run(guardrail_agent, input_data, context=ctx.context)
final_output = result.final_output_as(HomeworkOutput)
return GuardrailFunctionOutput(
output_info=final_output,
tripwire_triggered=not final_output.is_homework,
)
triage_agent = Agent(
name="Triage Agent",
instructions="You determine which agent to use based on the user's homework question",
handoffs=[math_tutor_agent],
input_guardrails=[
InputGuardrail(guardrail_function=homework_guardrail),
],
)
async def main():
# Example: General/philosophical question
try:
result = await Runner.run(triage_agent, "What is the meaning of life?")
print(result.final_output)
except InputGuardrailTripwireTriggered as e:
print("Guardrail blocked this input:", e)
if __name__ == "__main__":
asyncio.run(main())
![]() I might try a fix this week-end will keep you posted! |
Resolves #889